package com.ksd.pug.controller.articlecategory;

import com.ksd.pug.commons.anno.PugLog;
import com.ksd.pug.commons.anno.PugPermissionIngore;
import com.ksd.pug.config.anno.LoginCheck;
import com.ksd.pug.controller.BaseController;
import com.ksd.pug.pojo.ArticleCategory;
import com.ksd.pug.service.articlecategory.IArticleCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: hcl
 * @date: 2022/1/24 14:59
 * @Description:
 */
@RestController
@RequiredArgsConstructor
@Slf4j
public class ArticleCategoryController extends BaseController {

    private final IArticleCategoryService CategoryService;
    /**
     * 查询产品分类
     *
     * @return
     */
    @LoginCheck
    @PugPermissionIngore
    @GetMapping("/article/categories")
    public List<ArticleCategory> findArticleCategories() {
        return CategoryService.findCategories();
    }

    @GetMapping("/article/categories2")
    public List<ArticleCategory> findArticleCategories2() {
        return CategoryService.findCategories();
    }
    @GetMapping("/craetion/categories")
    public List<ArticleCategory> findArticleCategories3() {
        return CategoryService.findCategories();
    }


    /**
     * 保存和修改分类
     *
     * @return
     */
    @PostMapping("/article/savecategory")
    @PugLog(title = "保存或修改分类")
    public ArticleCategory saveCategory(@RequestBody ArticleCategory Category) {
        boolean flag = CategoryService.saveOrUpdate(Category);
        return flag ? Category : null;
    }

    /**
     * 根据id删除分类
     *
     * @return
     */
    @PostMapping("/article/category/del/{id}")
    public boolean saveCategory(@PathVariable("id") Long id) {
        ArticleCategory category = new ArticleCategory();
        category.setId(id);
        category.setIsdelete(1);
        return CategoryService.updateById(category);
    }

    /**
     * 根据id查询分类明细
     *
     * @return
     */
    @GetMapping("/article/category/get/{id}")
    public ArticleCategory getCategory(@PathVariable("id") Long id) {
        return CategoryService.getById(id);
    }
}
